/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.server.urls;

import java.util.HashMap;
import java.util.Map;
import org.restlet.util.Template;

/**
 *
 * @author selkhateeb
 */
public abstract class UrlBase {

    public UrlBase() {
    }
    protected Patterns urlpatterns;

    public Patterns getUrlpatterns() {
        return urlpatterns;
    }

    public Pattern parse(String pathInfo) {
        for (Pattern pattern : urlpatterns.getPatterns()) {
            Template t = new Template(pattern.getUriTemplate());
            Map<String, Object> variables = new HashMap<String, Object>();
            if (t.parse(pathInfo, variables) != -1) {
                pattern.setMethodParams(variables);
                return pattern;
            }
        }

        return null;
    }
}
